home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
lib
/
mntlib44.zoo
/
mntlib
/
unx2dos.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-16
|
3KB
|
209 lines
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <osbind.h>
#include <types.h>
#include <param.h>
#include <support.h>
#include "lib.h"
extern int __mint;
extern char _rootdir; /* in main.c: user's preferred root directory */
int _unixmode; /* not used right now */
/*
* returns 0 for ordinary files, 1 for special files (like /dev/tty)
*/
int
_unx2dos(unx, dos)
const char *unx;
char *dos;
{
const char *u;
char *d, c;
dos[0] = 0;
u = unx; d = dos;
if (!strncmp(u, "/dev/", 5)) {
u += 5;
/* make /dev/A/foo the same as A:/foo */
if (*u && isalpha (*u)
&& (u[1] == 0 || (u[1] == '/' || u[1] == '\\'))) {
d[0] = *u++;
d[1] = ':';
d += 2;
}
/* check for a unix device name */
else if (__mint) {
if (__mint >= 8) {
strcpy(d, "U:\\dev\\"); d += 7;
} else {
strcpy(d, "V:\\");
d += 3;
}
}
else {
strcpy(d, u);
strcat(d, ":");
if (!strcmp(d, "tty:"))
strcpy(d, "con:");
return 1;
}
} else if (__mint && !strncmp(u, "/pipe/", 6)) {
u += 6;
if (__mint >= 9) {
strcpy(d, "U:\\pipe\\"); d += 8;
} else {
strcpy(d, "Q:\\"); d += 3;
}
} else if (*u == '/' && _rootdir) {
*d++ = _rootdir;
*d++ = ':';
}
while( (c = *u++) != 0 ) {
if (c == '/')
c = '\\';
#if 0
/* translate "c:/foo/d:/bar" into "d:\bar" */
else if (c == ':') {
if ( (d > &dos[1] && d[-2] == '\\')
|| (d == &dos[1]) ) {
*dos = d[-1];
d = dos+1;
}
}
#endif
*d++ = c;
}
*d = 0;
return 0;
}
int
_dos2unx(dos, unx)
const char *dos;
char *unx;
{
register char c;
/* replace A:\x with /dev/a/x,
* replace A:\x with /x, if _rootdir is 'a',
* replace A:\x with /a/x, if _rootdir is 'u'.
* BUG/FEATURE: A:x is converted to A:\x, you lose the feature
* of one current directory per device.
* This is because we assume that /dev/a/x is always
* an absolute path.
*/
if (*dos && dos[1] == ':') {
register char dev = tolower(*dos);
dos += 2;
if (dev != _rootdir) {
if (_rootdir != 'u') {
*unx++ = '/'; *unx++ = 'd';
*unx++ = 'e'; *unx++ = 'v';
}
*unx++ = '/';
*unx++ = dev;
}
if (*dos != '/' && *dos != '\\') {
*unx++ = '/';
}
}
/* convert slashes
*/
while ( (c = *dos++) != 0) {
if (c == '\\')
c = '/';
else if (__mint < 7)
c = tolower(c);
*unx++ = c;
}
*unx = 0;
return 0;
}
#ifdef __GNUC__
asm(".stabs \"_unx2dos\",5,0,0,__unx2dos"); /* dept of clean tricks */
asm(".stabs \"_dos2unx\",5,0,0,__dos2unx"); /* dept of clean tricks */
#else /* ! __GNUC__ */
int
unx2dos(unx, dos)
const char *unx;
char *dos;
{
return _unx2dos(unx, dos);
}
int
dos2unx(dos, unx)
const char *dos;
char *unx;
{
return _dos2unx(dos, unx);
}
#endif
int
_path_unx2dos(unx, dos)
const char *unx;
char *dos;
{
char buf[MAXPATHLEN], *s;
while (*unx) {
s = buf;
while (*unx) {
if (*unx == ':') {
unx++;
break;
}
*s++ = *unx++;
}
*s = 0;
_unx2dos(buf, dos);
while (*dos)
dos++;
if (*unx)
*dos++ = ',';
}
*dos = 0;
return 0;
}
int
_path_dos2unx(dos, unx)
const char *dos;
char *unx;
{
char buf[MAXPATHLEN], *s;
while (*dos) {
s = buf;
while (*dos) {
if (*dos == ';' || *dos == ',') {
dos++;
break;
}
*s++ = *dos++;
}
*s = 0;
_dos2unx(buf, unx);
while (*unx)
unx++;
if (*dos)
*unx++ = ':';
}
*unx = 0;
return 0;
}